/**
 * 功能描述 卡片
 */

define(function (require, exports, module) {
	var aw = require("ajaxwrapper")
	var Form = require("form");
	var Dialog = require("dialog");
	var store =require("store");
	var activeUser = store.get("user");	
	
    var instance = {
        initComponent: function (params,widget) {
        	var form=new Form({
       		 show:false,
        	 parentNode:".J-form",
       		 saveaction : function(){
       			 var data=form.getData();
       			 aw.saveOrUpdate("api/destination/save",data,function(data){
       				 widget.get("form").upload("photo","api/attachment/destination/destinationphoto"+"_"+data.pkDestination);
       				 widget.get("grid").refresh();
					 widget.show([".J-grid"]).hide([".J-form"]);
					 widget.get("subnav").hide(["return"]).show(["add","search"]);
       			 });
       		 },
       		 cancelaction : function(){
       			     widget.show([".J-grid"]).hide([".J-form"]);
					 widget.get("subnav").hide(["return"]).show(["add","search"]);
					 widget.get("grid").refresh();
       		 },
	  			 model:{
	  				layout:"2_1",
					id:"visitway",
					items:[{
						name:"pkDestination",
						type:"hidden"
					},{
						name:"organization",
					    type:"hidden",
					    defaultValue:activeUser.organization.pkOrganization
					},{
						name:"status",
					    type:"hidden",
					    defaultValue:"Setting"
					},{
						name:"version",
						type:"hidden",
						defaultValue:"0"
					},{
						name:"name",
						id:"name",
						label:"目的地名称",
						validate:["required"]
					},{
						name:"address",
						type:"place",
						label:"省/市/区（县）",
						validate:["required"]
					},{
						name:"street",
						label:"乡（镇）/社区"
					},{
						name:"contact",
						label:"联系人"
					},{
						name:"phone",
						label:"联系电话"
					},{
						name:"photo",
						type:"file",
						label:"照片",
						accept:"jpg,gif",
						isPreview:true
					},{
						name:"introduce",
						type:"textarea",
						label:"目的地介绍",
						height:100,
						"break":true,
						exValidate: function(value){
							if(value.length>256){
								return "介绍不能超过256个字";
							}else{
								return true;
							}
						}
					},{
						name:"description",
						type:"textarea",
						label:"备注",
						height:100,	
						"break":true,
						exValidate: function(value){
							if(value.length>256){
								return "备注不能超过256个字";
							}else{
								return true;
							}
						}
					}]
				 }
       	 });
       	 widget.set("form",form);
       	 $(".J-form-visitway-file-photo :button").addClass('btn btn-theme');
        }
    };
    module.exports = instance;
});
